#include <sys/signal.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

/***
 * 基于poxis1的 abort实现
 **/
void abort(void)
{
    sigset_t mask;
    struct sigaction action;
    sigaction(SIGABRT,NULL, &action);

    if(action.__sigaction_u.__sa_handler == SIG_IGN)
    {
        action.__sigaction_u.__sa_handler = SIG_DFL;
        sigaction(SIGABRT, &action, NULL);
    }

    if(action.__sigaction_u.__sa_handler == SIG_DFL)
    {
        fflush(NULL);
    }
    
    sigfillset(&mask);
    sigdelset(&mask, SIGABRT);
    sigprocmask(SIG_SETMASK, &mask, NULL);

    kill(getpid(), SIGABRT);

    fflush(NULL);

    action.__sigaction_u.__sa_handler = SIG_DFL;
    sigaction(SIGABRT, &action, NULL);
    sigprocmask(SIG_SETMASK, &mask, NULL);

    kill(getpid(), SIGABRT);
    exit(1);
}

